<template>
	<view class="container">
		<view class="content-title" v-text="detail.title">
		
		</view>
		<view class="fubiaoti">
			<view v-text="detail.source + ' '+detail.time"> </view>
			<view class="shoucang" @click="shoucang" v-if="!like"> 收藏 </view>
			<view class="shoucang" @click="shoucang" v-else> 已收藏 </view>
		</view>
		<view class="content">
		<jyf-parser :lazy-load="lazy" :cache="cache"  :html="html" ref="article"></jyf-parser>
		</view>
		<!-- 猜你喜欢 -->
		<view class="card">
			<view class="card-title">
				<view>
					相关资讯
				</view>
				<navigator url="/pages/gonglue/gonglue" open-type="switchTab" class="card-right">
					查看更多 <view class="iconfont icon-qianjin icon-small"></view>
				</navigator>
			</view>
			<view class="card-info1">
				<uni-gonglue :item="item1" opentype="redirect" v-for="(item1,index1) in list" :key="index1"></uni-gonglue>
			</view>
		</view>
		<uni-footer></uni-footer>
	</view>
</template>

<script>
	import jyfParser from "@/components/jyf-parser/jyf-parser";
	export default {
	onShareAppMessage() {
		return {
			title: this.detail.title,
			path: '/pages/gonglue/detail?id=' + this.id,
			desc: '',
			controls: true,
			imageUrl: this.detail.img
		}
		},
		data() {
			return {
				detail: {
					'title':'',
					'img':'',
					'source':'',
					'time':'',
					'contents':'',
				},
				id: '',
				list: [],
				html: '',
				like: 0,
				lazy:true,
				cache:true
			}
		},
		components: {
			jyfParser
		},
		onLoad: function(option) {
		// #ifdef MP-TOUTIAO
		/* 	let token = uni.getStorageSync('token')
			if(!token){
				uni.reLaunch({
					url:"/pages/login/login"
				})
			} */
			
			// #endif 
			
			//#ifdef MP-TOUTIAO
				this.$toutiao(29)
			//#endif
			console.log(option)
			this.id = option.id
			this.$api.getNewsDetail({
				id: this.id
			}).then(
				res => {

					this.detail = res.data
					this.html = this.detail.contents;
					uni.setNavigationBarTitle({
						title: this.detail.title
					})

				}
			)
			this.getNews()
		},
		onShow() {
			this.isLike()
		},
		onReady() {
			


		},
		methods: {
			getNews() {
				this.$api.getNews({
						id: this.id
					}).then(res => {
						this.list = res.data
					})
			},
			isLike(){
				this.$api.isLikeFactory({	type: 0,
					source_type: 1,
					model_id:this.id}).then(res=>{
						this.like=res.data
					})
			},
			shoucang() {
				this.$api.likeFactory({
					type: 0,
					source_type: 1,
					model_id:this.id
				}).then(
					res => {
						this.like = 1-this.like 
					}
				)
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding-left: 31rpx;
		padding-right: 31rpx;
		padding-top: 8rpx;
		.rich {
			max-width: 690rpx;
		}
		.content{
			margin-top: 40rpx;
			width: 100%;
			overflow: hidden;
		}
		.content-title {
			font-size: 48rpx;
			font-family: SourceHanSansCN;
			font-weight: bold;
			color: rgba(73, 73, 73, 1);
		}
		.content-to {
			text-align: center;
		}

		.fubiaoti {
			font-size: 24rpx;

			font-family: SourceHanSansCN;
			font-weight: 500;
			height: 50rpx;
			display: flex;
			align-items: flex-end;
			justify-content: space-between;
			color: rgba(154, 155, 160, 1);

			.shoucang {
				width: 100rpx;
				height: 40rpx;
				background: rgba(218, 51, 55, 1);
				display: flex;
				justify-content: center;
				align-items: center;
				color: #FFFFFF;
				border-radius: 20rpx;
			}
		}

		.card {
			background-color: #FFFFFF;
			border-radius: 10rpx;
			margin-bottom: 35rpx;

			.card-avatar {
				height: 136rpx;
				border-bottom: 2rpx solid #F3F3F3;
				display: flex;
				justify-content: space-between;
				padding-left: 25rpx;
				padding-top: 41rpx;

				.card-view {
					width: 259rpx;
					height: 78rpx;
					display: flex;
					.card-text {
						display: flex;
						flex-direction: column;
						justify-content: center;
						.card-text-top {
							font-size: 34rpx;
							font-weight: bold;
							color: rgba(0, 0, 0, 1);
						}
						.card-text-bottom {
							font-size: 24rpx;
							font-weight: 400;
							color: rgba(67, 68, 70, 1);
						}
					}
				}
			}

			.card-title {
				height: 89rpx;
				border-bottom: 2rpx solid #F3F3F3;
				color: #313131;
				font-size: 34rpx;
				font-weight: bold;
				padding: 25rpx;
				display: flex;
				justify-content: space-between;

				.card-right {
					font-size: 24rpx;
					font-family: SourceHanSansCN;
					font-weight: 500;
					color: rgba(73, 73, 73, 1);
					display: flex;
					line-height: 60rpx;
				}
			}

			.card-info1 {

				padding-bottom: 43rpx;
			}

			.card-info {
				padding-top: 30rpx;
				padding-left: 25rpx;
				padding-right: 17rpx;
				padding-bottom: 43rpx;

				.park {
					height: 349rpx;
					width: 100%;
					border-radius: 10rpx;
					margin-bottom: 33rpx;
				}

				.xinxi {
					display: flex;
					justify-content: center;

					.left {
						width: 50%;
						display: flex;
						flex-direction: column;
						align-items: flex-start;
					}

					.right {
						width: 50%;
						display: flex;
						flex-direction: column;
						align-items: flex-start;
					}

				}
			}

		}

	}
</style>
